/*
 * light.c
 *
 *  Created on: May 23, 2021
 *      Author: kirk_
 */

#include "light.h"

KDL_LED_t Light[4];

void Light_Init(void)
{
	KDL_LED_Init(&Light[0], LED0_GPIO_Port, LED0_Pin, KDL_LED_ONSTATE_LOW);
	KDL_LED_Init(&Light[1], LED1_GPIO_Port, LED1_Pin, KDL_LED_ONSTATE_LOW);
	KDL_LED_Init(&Light[2], LED2_GPIO_Port, LED2_Pin, KDL_LED_ONSTATE_LOW);
	KDL_LED_Init(&Light[3], LED3_GPIO_Port, LED3_Pin, KDL_LED_ONSTATE_LOW);
}


uint32_t Light_Turn(uint32_t index, uint32_t state)
{
	if(index>=4)
		return 3;
	switch(state)
	{
	case 0:
		KDL_LED_TurnOff(&Light[index]);
		return 0;
		break;
	case 1:
		KDL_LED_TurnOn(&Light[index]);
		return 1;
		break;
	default:
		KDL_LED_Toggle(&Light[index]);
		return 2;
	}
}

void StartBeatLightThread(void *argument)
{
  /* USER CODE BEGIN StartBeatLightThread */
  /* Infinite loop */
	for(;;)
	{
		Light_Turn(1, 0);
		osDelay(699);
		Light_Turn(1, 2);
		osDelay(99);
		Light_Turn(1, 2);
		osDelay(99);
		Light_Turn(1, 2);
		osDelay(99);
	}
  /* USER CODE END StartBeatLightThread */
}
